import { listChat, fakeAnswerRecordsData, fakeAnswerRelevanceData, fakeAnswerRelevanceUpDownData, fakeAnswerRelevanceknowledgeData, doIgoreRecord, doDoctorList, doHandlerList } from '@/services/datastatistics';
import { cognatesList, cognatesListNewAlter } from '@/services/basiccapacity';
export default {
  namespace: 'answerRecords', // model的名字 用来在页面中找到要调用的那一个model

  state: {
    list: [],
    suggestList: [],
    qaList: [],
  },

  effects: {
    *fetch({ payload, callback }, { call, put }) {
      const response = yield call(fakeAnswerRecordsData, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *listChat({ payload, callback }, { call, put }) {
      const response = yield call(listChat, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *fetchb({ payload, callback }, { call, put }) {
      const responses = yield call(fakeAnswerRelevanceData, payload);
      if (responses) {
        if (callback && typeof callback === 'function') {
          callback(responses);
        }
        yield put({
          type: 'saves',
          payload: responses,
        });
      }
    },
    *fetchc({ payload, callback }, { call, put }) {
      const responseA = yield call(fakeAnswerRelevanceUpDownData, payload);
      if (responseA) {
        if (callback && typeof callback === 'function') {
          callback(responseA);
        }
        yield put({
          type: 'saveA',
          payload: responseA,
        });
      }
    },
    *fetchd({ payload, callback }, { call, put }) {
      const responseB = yield call(fakeAnswerRelevanceknowledgeData, payload);
      if (responseB) {
        if (callback && typeof callback === 'function') {
          callback(responseB);
        }
        yield put({
          type: 'saveB',
          payload: responseB,
        });
      }
    },
    *getSynonym({ payload, callback }, { call, put }) {
      const responseB = yield call(cognatesList, payload);
      if (responseB) {
        if (callback && typeof callback === 'function') {
          callback(responseB);
        }
        yield put({
          type: 'saveB',
          payload: responseB,
        });
      }
    },
    *doSubmit({ payload, callback }, { call, put }) {
      const responseB = yield call(cognatesListNewAlter, payload);
      if (responseB) {
        if (callback && typeof callback === 'function') {
          callback(responseB);
        }
        yield put({
          type: 'saveB',
          payload: responseB,
        });
      }
    },
    *igoreRecord({ payload, callback }, { call, put }) {
      const responseB = yield call(doIgoreRecord, payload);
      if (responseB) {
        if (callback && typeof callback === 'function') {
          callback(responseB);
        }
        yield put({
          type: 'saveB',
          payload: responseB,
        });
      }
    },
    *fetchDoctorList({ payload, callback }, { call, put }) {
      const responseB = yield call(doDoctorList, payload);
      if (responseB) {
        if (callback && typeof callback === 'function') {
          callback(responseB);
        }
        yield put({
          type: 'saveB',
          payload: responseB,
        });
      }
    },
    *fetchHandlerList({ payload, callback }, { call, put }) {
      const responseB = yield call(doHandlerList, payload);
      if (responseB) {
        if (callback && typeof callback === 'function') {
          callback(responseB);
        }
        yield put({
          type: 'saveB',
          payload: responseB,
        });
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    fetchb(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    fetchc(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    fetchd(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    clear() {
      return {
        list: [],
        suggestList: [],
        qaList: [],
      };
    },
  },
};
